package cn.itcast.order.controller;

import cn.itcast.hmall.dto.common.ResultDTO;
import cn.itcast.hmall.dto.order.OrderReqDTO;
import cn.itcast.hmall.pojo.order.Order;
import cn.itcast.hmall.pojo.user.User;
import cn.itcast.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author oldwine
 * @date 2022/6/22
 * @Version 1.0
 */
@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;


    /**
     * 根据订单id查询订单
     *
     * @param orderId 订单id
     * @return 返回订单详情
     */
    @GetMapping("/order/{orderId}")
    public Order selectOrderById(@PathVariable("orderId") Long orderId) {
        return orderService.getById(orderId);
    }

    /**
     * 创建订单方法
     *
     * @param vo 封装请求参数的对象
     * @return 结果
     */
    @PostMapping("/order")
    public String createOrder(@RequestBody OrderReqDTO vo) {
        return orderService.createOrder(vo);
    }

    /**
     * 支付订单功能
     * @param orderId 订单id
     * @param password 支付密码
     * @return 返回结果
     */
    @PutMapping("/pay/{orderId}")
    public ResultDTO payOrder(@PathVariable("orderId") Long orderId, @RequestBody String password) {
        return orderService.payOrder(orderId, password);
    }
}
